<include file="Common/common" />
<style type="text/css">
	input::-webkit-input-placeholder {
		color: rgb(201,211,215);
	}
	input:-ms-input-placeholder{
		color: rgb(201,211,215);
	}
	input::-moz-placeholder, textarea::-moz-placeholder {
		color: rgb(201,211,215);
	}input::-webkit-input-placeholder {
		 color: rgb(201,211,215);
	 }
	input:-ms-input-placeholder{
		color: rgb(201,211,215);
	}
	input::-moz-placeholder, textarea::-moz-placeholder {
		color: rgb(201,211,215);
	}
	</style>
<body>
	
	<div class="layui-tab-item layui-show">
		<div class="layui-main">
			<br>
			<blockquote class="layui-elem-quote" style=" color: rgb(240,222,112);background: rgb(57,61,73)">
				您当前的动态秘钥:{$userInfo['key_dynamic']}
			</blockquote>

			<form class="layui-form" id="giveReg-form" action="">
				<div class="layui-form-item">
					<label style=" color: rgb(240,222,112);" class="layui-form-label">赠送数量</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="number" step="0.1" name="num" lay-verify="required|number" min="0" max="{$userInfo['key_dynamic']}" onkeyup="checknum(this);"  autocomplete="off" placeholder="最大可转出{$userInfo['key_dynamic']}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label style=" color: rgb(240,222,112);" class="layui-form-label">接收账号</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="text" name="account" onblur="func_receive(this);" value="" lay-verify="required" placeholder="请填写转出账号"  autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label style=" color: rgb(240,222,112);" class="layui-form-label">接收方姓名</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="text" id="truename" name="truename" value="" lay-verify=""  autocomplete="off" placeholder="" class="layui-input" disabled="">
					</div>
				</div>
				<div class="layui-form-item">
					<label style=" color: rgb(240,222,112);" class="layui-form-label">安全密码</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="password" name="safe_password" value="" lay-verify="required"  autocomplete="off" placeholder="请填写安全密码" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block" >
						<button  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn" lay-submit="" lay-filter="btn-giving">确认</button>
					</div>
				</div>
			</form>
			<br><br><br>
			<div style="overflow-x: auto;">
				<table class="layui-table" style=" color: rgb(240,222,112);" >
					<thead>
							<tr style="background: rgb(57,61,73)">
								<th>编号</th>
								<th>接受用户</th>
								<th>交易数量</th>
								<th>交易时间</th>
							</tr> 
						</thead>
						<tbody>
							<foreach name="givingList" item="vo">
								<tr style="background: #7d7d7d;color:rgb(240,222,112);">
									<td>{$vo['id']}</td>
									<td>{$vo['receive_account']}</td>
									<td>{$vo['num']}</td>
									<td><?php if(!empty($vo['createtime'])){echo date('Y-m-d H:i:s',$vo['createtime']);} ?></td>
								</tr>
							</foreach>
						</tbody>
				</table>
				<div class="green-black">{$page}</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	// 验证数字
   	function checknum(obj){   
     	if(/^\d+\.?\d{0,1}$/.test(obj.value)){
        	obj.value = obj.value;
     	}else{
        	obj.value = obj.value.substring(0,obj.value.length-1);
     	}     
   	}

   	// 获取转出账号姓名
   	function func_receive(obj){
   		var receive_account = obj.value.trim();
   		
   		$.ajax({
            type: "post",
            url: "{:U('Member/ctrl_getReceive')}",
            data: {account:receive_account},
            dataType: "json",
            success: function(rtJson){
            	if (rtJson.code == 1) {
            		$("#truename").val(rtJson.name);
               	}else{
               		$("#truename").val('');
               	}
            }
        });
   	}

   	var maxnum = {$userInfo['key_dynamic']};
   	var now_account = "{$userInfo['account']}";

	layui.use(['upload','layedit'], function(){
		var form = layui.form,
		layer = layui.layer,
		layedit = layui.layedit;

		var $ = layui.jquery
		,upload = layui.upload;


		form.render();

		//监听提交表单
		form.on('submit(btn-giving)', function(data){
			if (data.field.num.trim() == '' || data.field.account.trim() == '' || data.field.safe_password.trim() == '') {
                layer.msg('<span style="color: rgb(240,222,112);">信息不完整，请完善</span>');
				return false;
			}

			if (data.field.num.trim() > maxnum ) {
                layer.msg('<span style="color: rgb(240,222,112);">动态秘钥不足，请重新输入</span>');

				return false;
			}

			if (data.field.account.trim() == now_account) {
                layer.msg('<span style="color: rgb(240,222,112);">不可赠送给自己</span>');
                return false;
			}

			layer.confirm('确定赠送？',{offset:'none'},function(index){
				$.ajax({
		            type: "post",
		            url: "{:U('Member/ctrl_giving')}",
		            data: data.field,
		            dataType: "json",
		            success: function(rtJson){
		            	if (rtJson.code == 1) {
		            		$('#giveReg-form')[0].reset();//重置表单
                            layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
			               	setTimeout(function(){location.reload();}, 1000);
		               	}else{
                            layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		               	}
		            }
		        });
			});
			
	        return false;
		});
	});
</script>
<include file="Common/footer" />